// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';
// 申明请求对象
const routeRequest = {
    // dict请求的基本url
    BASE_URL :  confing.PRO_URL + "/route",
    // 请求的API
    list(page = 1,limit = 10,proRoute,callback){
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if(proRoute){
            if(proRoute.routeCode){
                url += "&routeCode=" +proRoute.routeCode;
            }
            if(proRoute.routeName){
                url += "&routeName=" +proRoute.routeName;
            }
            if(proRoute.enableFlag){
                url += "&enableFlag=" +proRoute.enableFlag;
            }
        }
        // 发送请求
        request.get(url,callback);
    },
    //全部分页请求
    get(page = 1,limit = 10,callback){
        // url
        let url = this.BASE_URL + "/get?page=" + page + "&limit=" + limit;
        // 发送请求
        request.get(url,callback);
    },
    //自动生成编号
    genRouteCode(callback){
        let url=this.BASE_URL+'/genRouteCode';
        request.get(url,callback);
    },
    //新增工单
    save(proRoute,callback){
       let url=this.BASE_URL+'/save';
       request.post(url,proRoute,callback);
    },
    deleteRoute(routeCode,callback){
        request.delete(this.BASE_URL+"/deletRoute?routeCode="+routeCode,callback);
    },
    updateRoute(proRoute,callback){
        let url=this.BASE_URL+'/update';
        console.log(url);
        request.post(url,proRoute,callback);   
    }
}

// 将dictRequest暴漏出去
export default routeRequest;